package com.eshop;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class AddToChart
 */
@WebServlet("/AddToChart")
public class AddToChart extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddToChart() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		String itemID = request.getParameter("productID");
		String nrOfUnits = request.getParameter("nrOfUnits");
		HttpSession session = request.getSession(true);
		session.setAttribute(itemID, nrOfUnits);
		
		out.println("<HTML><HEAD><TITLE>Product Adding</TITLE></HEAD>");
		out.println("<BODY>");
		
		out.println("<FORM method=\"GET\" action=\"Products.html\">");
		out.println("<INPUT TYPE=\"submit\" VALUE=\"Add More Items\">");
		out.println("</FORM>");
		
		out.println("<FORM method=\"GET\" action=\"ShoppingCart.html\">");
		out.println("<INPUT TYPE=\"submit\" VALUE=\"Check Cart\"  >");
		out.println("</FORM>");
		
		getServletContext().getRequestDispatcher("/Products.html").forward(request,response); 
		
		out.println("</BODY></HTML>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
